var temp = object(tempAbs);
temp.sampleInfos = [];
temp.address = true;
temp.read = function(obj,bn){
    bn.setSampleInfos();
    if (obj && obj.customerCode) {
        bn.setComboBox('customerCode', obj.customerCode);
    }
    $(".second-table .field input").each(function(){
        var id = $(this).attr('id');
        if(id && id.indexOf('sampleType_')<0){
            if($(this).hasClass('easyui-datebox')){
                bn.setDat(id);
            }else{
                var type = $(this).attr('type');
                if(type=='text' || type=='date' || type=='number'){
                    bn.setVl(id);
                }
            }
        }
    });
    $(".second-table .field select").each(function(){
        var id = $(this).attr('id');
        bn.setSel(id);
    });
    if(obj.sampleType){
        var sampleTypeArr = obj.sampleType.split(',');
        $("input:checkbox[name^='sampleType_']").each(function(i){
            var id = $(this).attr('name');
            setCkArr(id,sampleTypeArr[i]);
        });
    }

    var all = {};
    $(".second-table .group-field input").each(function(){
        var id = $(this).attr('id');
        all[id.split('_')[0]] = 1;
    });
    for(var key in all){
        bn.setCkGrp(key);
    }
    if(obj.nativePlace){
        var sf = obj.nativePlace.substring(0,obj.nativePlace.indexOf('省'));
        var sq = obj.nativePlace.substring(obj.nativePlace.indexOf('省')+1,obj.nativePlace.indexOf('市'));
        $('#nativePlace1').val(sf);
        $('#nativePlace2').val(sq);
    }

    //畸形儿
	var oafNum = obj.oafNum;
    $("input:checkbox[id^='ckTestOther_']").each(function (){
    	var id = $(this).attr("id");
    	if(id == "ckTestOther_-1" && oafNum == 0){
    		$("#"+id).attr("checked",true);
            $("#"+id).siblings("input:checkbox").removeAttr("checked");
    	}
    });

    /*var oafInfo = obj.ckTestOther;
    if(oafInfo == ""){
        $("input:checkbox[id^='ckTestOther_']").each(function (){
            var id = $(this).attr("id");
            if(id == "ckTestOther_-1"){
                $("#"+id).attr("checked",true);
                $("#"+id).siblings("input:checkbox").removeAttr("checked");
            }
        });
	}*/

    //身份证信息不可更改
    $("#idCard").attr("disabled","disabled");
    //展示免费券编码
    $("div.coupon-box").removeAttr("onclick").html("<span>免费券编码：</span>"+obj.couponNum);
}

temp.save = function(bn){
    bn.getSampleInfos(temp.sampleInfos);
    // bn.getComboGrid('customerCode');
    bn.vl('sampleNum');
    $(".second-table .field input").each(function(){
        var id = $(this).attr('id');
        if(id && id.indexOf('sampleType_')<0){
            var type = $(this).attr('type');
            if($(this).hasClass('easyui-datebox')){
                bn.dat(id);
            }else{
                if(type=='text'){
                    bn.vl(id);
                }else if(type=='date'){
                    bn.vl(id);
                }else if(type=='number'){
                    bn.vl(id);
                }
            }
        }
    });
    $(".second-table .field select").each(function(){
        var id = $(this).attr('id');
        bn.sel(id);
    });
    var sampleTypeArr = [];
    var countSampleType = {};
    $("input:checkbox[name^='sampleType_']").each(function(){
        countSampleType[$(this).attr('name')] = 1;
    });
    for(var key in countSampleType){
        var val = ckArr(key);
        if(val){
            sampleTypeArr.push(val);
        }
    }
    bn.obj.sampleType = sampleTypeArr.join(',');
    //处理单选框字段
    $(".group-field input").each(function(){
        if($(this).is(":checked")){
            var id = $(this).attr('id');
            var arr = id.split('_');
            bn.obj[arr[0]] = arr[1];
        }
    });
    if(bn.obj.nativePlace1){
        bn.obj['nativePlace'] = bn.obj.nativePlace1+'省'+bn.obj.nativePlace2+'市';
        delete bn.obj.nativePlace1;
        delete bn.obj.nativePlace2;
    }
    if(bn.obj.idCard){
        bn.obj.idCard  = bn.obj.idCard.toUpperCase();
    }
}
temp.validateAbs = function(m){
    var msg = '';
    if(m) msg += m;
    return msg;
}
//组合复选框变单选框
$(function(){
    var p1 = null;
    var sortIndex = 1;
    $(".sample-type").each(function(index){
        var trArr = $(this).parent().parent().parent().parent().find('tr');
        var tTrArr = [];
        for(var i=0;i<trArr.length;i++){
            tTrArr.push(trArr[i]);
        }
        if(index==0){
            p1 = $(this).parent()[0];
            $(this).children("input:eq(0)").attr('name',"sampleType_"+sortIndex);
        }else{
            if(p1 != $(this).parent()[0] && Math.abs(tTrArr.indexOf(p1.parentNode)-tTrArr.indexOf($(this).parent().parent()[0]))>1){
                sortIndex++;
            }
            p1 = $(this).parent()[0];
            $(this).children("input:eq(0)").attr('name',"sampleType_"+sortIndex);
        }
    });
    var countObj = {};//统计有多少组需要单选的checkbox
    $(".second-table .group-field input").each(function(){
        var name = $(this).attr("name");
        countObj[name] = 1;
    });
    $(".second-table .sample-type input").each(function(){
        var name = $(this).attr("name");
        countObj[name] = 1;
    });
    for(var key in countObj){
        $("input[type=checkbox][name='"+key+"']").click(function(){
            if($(this).is(':checked')){
                if($(this).siblings('input').length>0){
                    $(this).siblings('input').attr('checked',false);
                }else{
                    $(this).parent('span').siblings().children('input').attr('checked',false);
                }
            }
        });
    }
    $("input:checkbox[id^='product_']").each(function(){
        var id = $(this).attr('id');
        temp.sampleInfos.push({productCode:id.split('_')[1],projectCode:''});
    });

   // $("#saveBtn").show();
});

var SPLIT1 = "W+";
var SPLIT2 = "-";
function readExtends(obj,bn){
	var gestationalWeeks = obj.gestationalWeeks;
	if(gestationalWeeks){
		var gwks = gestationalWeeks.split('W+');
		$("#gestationalWeeks1").val(gwks[0]);
		$("#gestationalWeeks2").val(gwks[1])
	}
	//处理免费类型字段，该字段在info表上
	if(obj.sampleInfos && obj.sampleInfos.length>0){
		var freeType = obj.sampleInfos[0].freeType;
		if(freeType){
			$("#freeType").val(freeType);
		}
	}
	if(obj.ntGestationalWeeks){
		var value = obj.ntGestationalWeeks;
		if(value.indexOf('w')>=0 && value.indexOf('d')>=0){
			$("#ntGestationalWeeks1").val(value.substring(0,value.indexOf('w')));
			$("#ntGestationalWeeks2").val(value.substring(value.indexOf('w')+1,value.indexOf('d')));
		}else if(value.indexOf('w')<0 && value.indexOf('d')>=0){
			$("#ntGestationalWeeks2").val(value.substring(0,value.indexOf('d')));
		}else if(value.indexOf('w')>=0 && value.indexOf('d')<0){
			$("#ntGestationalWeeks1").val(value.substring(0,value.indexOf('w')));
		}
	}
	if(obj.personalReproductiveHistory){
		var arr = obj.personalReproductiveHistory.split(SPLIT2);
		$("#personalReproductiveHistory1").val(arr[0]);
		$("#personalReproductiveHistory2").val(arr[1]);
	}
}
function saveExtends(bn){
	//处理孕周字段
	var gestationalWeeks1 = $("#gestationalWeeks1").val();
	var gestationalWeeks2 = $("#gestationalWeeks2").val();
	bn.obj.gestationalWeeks = gestationalWeeks1+"W+"+gestationalWeeks2;
	//处理免费类型字段，该字段在info表上
	var infos = bn.obj.sampleInfos;
	for(var i=0;i<infos.length;i++){
		infos[i]["freeType"] = $("#freeType").val();
	}
	//超声检测孕周
	var value = '';
	if($("#ntGestationalWeeks1").val()){
		value += $("#ntGestationalWeeks1").val()+'w';
	}
	if($("#ntGestationalWeeks2").val()){
		value += $("#ntGestationalWeeks2").val()+'d';
	}
	bn.obj.ntGestationalWeeks = value;
	//生育史
	var v1 = $("#pregnancyNum").val()||'';
	var v2 = $("#produceNum").val()||'';
	bn.obj.personalReproductiveHistory = v1+SPLIT2+v2;
}
temp.validateAbs = function(m){
	var msg = '';
	if(m) msg += m;
	
	var g1 = $("#gestationalWeeks1").val();
	var g2 = $("#gestationalWeeks2").val();
	if(!g1 && !g2){
		msg += '<li>孕周不能为空!</li>';
	}
	return msg;
}
$.event.special.valuechange = {
	teardown : function(namespaces) {
		$(this).unbind('.valuechange');
	},
	handler : function(e) {
		$.event.special.valuechange.triggerChanged($(this));
	},
	add : function(obj) {
		$(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange',
				obj.selector, $.event.special.valuechange.handler);
	},
	triggerChanged : function(element) {
		var current = element[0].contentEditable === 'true' ? element.html() : element.val()
		, previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
		if (current !== previous) {
			element.trigger('valuechange', [ element.data('previous') ]);
			element.data('previous', current);
		}
	}
}
$(function(){
	if(isChrome){
		$('#bloodDate').on('valuechange', function (e, previous) {
			autoGestationalWeeks();
	    	 $("#applyTime").val($("#bloodDate").val());
	    });
		$('#lmp').on('valuechange',function(e,previous){
			$("#edd").val(operationEdd($('#lmp').val()));
			autoGestationalWeeks();
		})
	}else{
		$('#bloodDate').datebox({
		    onSelect: function(date){
		    	autoGestationalWeeks();
		    	$("#applyTime").datebox('setValue',date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
		    }
		});
		$('#lmp').datebox({
		    onSelect: function(date){
		    	autoGestationalWeeks();
		    	$("#edd").datebox('setValue',operationEdd(date.getFullYear()+"-"+((date.getMonth()+1)>=10?(date.getMonth()+1):"0"+(date.getMonth()+1))+"-"+(date.getDate()>=10?date.getDate():"0"+date.getDate())));
		    }
		});
	}
	
	$("#idCard").on('valuechange', function (e, previous) {
		autoBirthDayAndAge();
	});

	
	$("#trisomy21").on('valuechange', function (e, previous) {
		autoMotherSerumRisk();
	});
	$("#trisomy18").on('valuechange', function (e, previous) {
		autoMotherSerumRisk();
	});
});

function autoGestationalWeeks(){
	var lmpDate = "";
	var bloodDate = ""
	if(isChrome){
		if($("#lmp").val()){
			lmpDate = $("#lmp").val();
		}
		if($("#bloodDate").val()){
			bloodDate = $("#bloodDate").val();
		}
	}else {
		if($("#lmp").datebox("getValue")){
			lmpDate = $("#lmp").datebox("getValue");
		}
		if($("#bloodDate").datebox("getValue")){
			bloodDate = $("#bloodDate").datebox("getValue");
		}
	}
	
	var lmpDay = Math.abs(new Date(Date.parse(lmpDate.replace(/-/g,  "/"))));
	var bloodDay = Math.abs(new Date(Date.parse(bloodDate.replace(/-/g,  "/"))));
	if(bloodDay>=lmpDay){
		console.log(((bloodDay-lmpDay)/(1000 * 60 * 60 * 24))%7);
		$("#gestationalWeeks1").val("");
		$("#gestationalWeeks2").val("");
			if(((bloodDay-lmpDay)/(1000 * 60 * 60 * 24))%7==0){
				$("#gestationalWeeks1").val(((bloodDay-lmpDay)/(1000 * 60 * 60 * 24))/7);
			}else {
				var weeks = (((bloodDay-lmpDay)/(1000 * 60 * 60 * 24)-(((bloodDay-lmpDay)/(1000 * 60 * 60 * 24))%7)))/7;
				var days = ((bloodDay-lmpDay)/(1000 * 60 * 60 * 24))%7;
				$("#gestationalWeeks1").val(weeks);
				$("#gestationalWeeks2").val(days);
			}
	};
	
}

function autoMotherSerumRisk(){
	var TRISOMY21 = 0;
	var TRISOMY18 = 0;
	var value18 = 0;
	var value21 = 0;
	if($("#trisomy18").val()){
		TRISOMY18 = parseInt($("#trisomy18").val());
	}
	if($("#trisomy21").val()){
		TRISOMY21 = parseInt($("#trisomy21").val());
	}
	if(parseInt(0)<parseInt(TRISOMY18)&&parseInt(TRISOMY18)<=parseInt(350)){
		value18 = 3;
	}else if(parseInt(TRISOMY18)>parseInt(350)&&parseInt(TRISOMY18)<=parseInt(1000)){
		value18 = 2;
	}else if(parseInt(TRISOMY18)>parseInt(1000)){
		value18 = 1
	}
	if(parseInt(0)<parseInt(TRISOMY21)&&parseInt(TRISOMY21)<=parseInt(270)){
		value21 = 3;
	}else if(parseInt(TRISOMY21)>parseInt(270)&&parseInt(TRISOMY21)<=parseInt(1000)){
		value21 = 2;
	}else if(parseInt(TRISOMY21)>parseInt(1000)){
		value21 = 1
	}
	$("input[id^='motherSerumRisk_']").prop("checked",false);
	if(parseInt(value21)>parseInt(value18)){
		if(value21==3){
			$("#motherSerumRisk_0").prop("checked",true);
		}else if(value21==2){
			$("#motherSerumRisk_2").prop("checked",true);
		}else if(value21==1){
			$("#motherSerumRisk_1").prop("checked",true);
		}
	}else{
		if(value18==3){
			$("#motherSerumRisk_0").prop("checked",true);
		}else if(value18==2){
			$("#motherSerumRisk_2").prop("checked",true);
		}else if(value18==1){
			$("#motherSerumRisk_1").prop("checked",true);
		}
	}
}
function operationEdd(date){
	if(date.split('-')[1]<4){
		return addMonth(addDay(date,7),9);
	}else {
		return deleteMonth(addDay(date,7),3);
	}
}
//月份
function addMonth(sDate, num) {
    var aYmd = sDate.split('-');
    var dt = new Date(Date.parse(sDate.replace(/-/g,  "/")))
    //var dt = new Date(aYmd[1] + '-' + aYmd[2] + '-' + aYmd[0]); //转换为MM-DD-YYYY格式   
    dt.setMonth(dt.getMonth() + num);
    var y = dt.getFullYear();
    var m = dt.getMonth()+ 1;
    var d = dt.getDate();
    if (m == 0) { m = 12; y = y - 1; }

    if (m < 10) m = '0' + m;
    if (d < 10) d = '0' + d;
    return y + '-' + m + '-' + d;
}
function deleteMonth(sDate, num){
	//var aYmd = sDate.split('-');
	var dt = new Date(Date.parse(sDate.replace(/-/g,  "/")))
	//var dt = new Date(aYmd[1] + '-' + aYmd[2] + '-' + aYmd[0]); //转换为MM-DD-YYYY格式   
	console.log(dt);
    dt.setMonth(dt.getMonth() - num);
    dt.setFullYear(dt.getFullYear()+1);
    var y = dt.getFullYear();
    var m = dt.getMonth()+1;
    var d = dt.getDate();
    if (m == 0) { m = 12; y = y - 1; }

    if (m < 10) m = '0' + m;
    if (d < 10) d = '0' + d;
    return y + '-' + m + '-' + d;
}

//追加日
function addDay(dateTemp, days) {  
    var aYmd = dateTemp.split("-");  
    var nDate = new Date(Date.parse(dateTemp.replace(/-/g,  "/")))
   // var nDate = new Date(aYmd[1] + '-' + aYmd[2] + '-' + aYmd[0]); //转换为MM-DD-YYYY格式    
    var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);  
    var rDate = new Date(millSeconds);  
    var year = rDate.getFullYear();  
    var month = rDate.getMonth() + 1;  
    if (month < 10) month = "0" + month;  
    var date = rDate.getDate();  
    if (date < 10) date = "0" + date;  
    return (year + "-" + month + "-" + date);  
}  
/**
 * 根据保健编号调用后台接口获取相关信息
 */
function autoInfoByHealthNum(healthNum){
	$.ajax({
		async : true,
		cache:false,
		type: 'POST',
		dataType : "json",
		url:'wechat/getGravidaHealthInfo.action',
		data:{
			"healthInfo.healthNum":healthNum
		},
    	success:function(data){
    		var json = data.object;
    		if(json.name){
    			setVl('sampleName',json.name);
    		}
    		if(json.cardId){
    			setVl('idCard',json.cardId);
    		}
    		if(json.mobile){
    			setVl('motherPhoneNum',json.mobile);
    		}
    		if(json.birthDate){
    			if(isChrome){
    				setVl('birthDate',json.birthDate);
    			}else{
    				$("#birthDate").datebox('setValue',json.birthDate);
    			}
    		}
    		if(json.age){
    			setVl('sampleAge',json.age);
    		}
    		if(json.weight){
    			setVl('bodyWeight',json.weight);
    		}
    		if(json.height){
    			setVl('bodyHeight',json.height);
    		}
    		if(json.lastMenstrualPeriod){
    			setVl('lmp',json.lastMenstrualPeriod);
    		}
    		if(json.ivfFlag){
    			setVl('adosculation',json.ivfFlag);
    		}
    		if(json.gravidityTimes){//孕次
    			setVl('personalReproductiveHistory1',json.gravidityTimes);
    		}
    		if(json.parityTimes){
    			setVl('personalReproductiveHistory2',json.parityTimes);
    		}
    		if(json.abortionTimes){
    			setVl('naturalAbortionNum',json.abortionTimes);
    		}
    	}
	});
}
/**
 * 根据身份证号码自动解析生日和年龄
 */
function autoBirthDayAndAge(){
	var newValue = $("#idCard").val();
	if(newValue.length==18){
		//430726198810243118
		var birthday = newValue.substring(6,14);
		if(isChrome){
			$("#birthDate").val(birthday.substring(0,4)+"-"+birthday.substring(4,6)+"-"+birthday.substring(6));
		}else{
			$('#birthDate').datebox('setValue',birthday.substring(0,4)+"-"+birthday.substring(4,6)+"-"+birthday.substring(6));
		}
		$("#sampleAge").val(new Date().getFullYear()-Number(birthday.substring(0,4)));
		$("#birthDate").trigger('valuechange');
		$("#sampleAge").trigger('valuechange');
	}
}

function getAge(idCardNum){

    var birthYear= parseInt(idCardNum.substr(6,4));
    var dateObj=new Date();
    var currentYear= parseInt(dateObj.getFullYear());
    var currentAge=currentYear-birthYear;
    $("#sampleAge").val(currentAge) ;
}
//输完身份证带出年龄
function idCardBlur() {
    getAge($("#idCard").val());
}

//获取畸形儿类，B超异常，胎数信息
function getChoice(obj){
    var typeId=obj.id;
    var typeValue = $("#"+obj.id).data("value");
    var typeName = typeId.substr(0,typeId.indexOf("_"));
    $("#"+typeName+"-input").val(typeValue);
}

//不使用优惠券
$(".no-coupon").click(function () {
    $("#dnaMotherIdCard").removeAttr('disabled');
    $("#sampleName").removeAttr('disabled');
    $('#myModal').modal('hide');
    couponNum = '';
    $('.coupon-box').html('选择免费券');
});

//退出登录
function logout() {
    $.ajax({
        url: '/csfy/dologout.do',
        method: 'POST',
        success: function (res) {
            if (JSON.parse(res).code == 200) {
                window.location.href = "/csfy/index.do"
            }
        }
    })
}
//使用优惠券
var couponNum = '';

//受检者姓名
var sampleName = '';

function useCoupon(num) {
    //优惠券对应的身份证号码
    var id = $("#coupon-kw").val();
    //设置优惠券对应的身份证
    $("#idCard").val(id);
    //设置身份证输入框不可编辑
    $("#idCard").attr('disabled', 'disabled');

    //使用优惠券姓名
    $("#sampleName").val(sampleName);
    $("#sampleName").attr('disabled', 'disabled');

    $('#myModal').modal('hide');
    $('.coupon-box').html('免费券码：' + (num ? num : ''));

    //重置搜索列表
    $("#coupon-kw").val('');
    $(".coupon-list").html('');
    $(".empty-coupon").hide();

    couponNum = num;
}
//身份证号失去焦点
$("#idCard").blur(function () {
	var id = $("#idCard").val();
	$.ajax({
		method: 'POST',
		url: '/csfy/intf.do',
		data: {
			method: 'getDetailPresonInfo',
			id
		},
		success: function (res) {
			console.log(res)
			var couponList = '';
			sampleName = res.rows.name;
			if (res && res.code == 200) {
				var couponInfos = (res.rows && res.rows.couponInfos) || [];
				for(var i = 0;i < couponInfos.length;i++){
					if(couponInfos[i].productCode == "DX0558" && couponInfos[i].status == 1){
						couponNum = couponInfos[i].couponNum;
					}
				}
			}
		}
	});
});
//TODO 根据证件搜索优惠券
function searchCoupons() {
    var id = $("#coupon-kw").val();
    if (id) {
        $.ajax({
            method: 'POST',
            url: '/csfy/intf.do',
            data: {
                method: 'getDetailPresonInfo',
                id
            },
            success: function (res) {
                console.log(res)
                var couponList = '';
                sampleName = res.rows.name;
                $(".coupon-list").html('');
                $(".empty-coupon").html('正在搜索...');
                if (res && res.code == 200) {
                    var couponInfos = (res.rows && res.rows.couponInfos) || [];
                    if (couponInfos.length > 0) {
                        var mData = {};
                        mData.rows = couponInfos;
                        var html = template('coupon-list', mData);
                        $(".coupon-list").html(html);
                        $(".empty-coupon").hide();
                    } else {
                        $(".empty-coupon").html('未找到当前证件名下的免费券');
                    }
                } else {
                    $(".empty-coupon").html('未找到当前证件名下的免费券');
                }
            }
        });
    } else {
        $(".coupon-list").html('');
        $(".empty-coupon").show();
        $(".empty-coupon").html('没有找到免费券');
    }
}

//选择使用优惠券
function chooseCoupon() {
    $('#myModal').modal('show');
}
function save(cover) {
    //获取当前页面的子页面里面的属性值
    var msg = temp.validate();

    //获取模板字段。
    var obj = temp.saveAbs();

    //报错并退出
    if (msg) {
        sysErrorShow(msg);
        return false;
    }

    //校验孕周
	if($("#gestationalWeeks1").val() < 12 || $("#gestationalWeeks1").val() > 40){
		alert("孕周范围为：12~40周");
		return false;
	}

    //数据过滤 start
    var params = {};
    Object.keys(obj).map(key => {
        var prototype = Object.prototype.toString.call(obj[key]);
    if ('[object String]' === prototype && obj[key]) {
        params[key] = obj[key];
    }
});
    params.productName = 'NIPT检测';
    params.productCode = 'DX0558';
    if (couponNum) {
        params.couponNum = couponNum;
    }else {
		alert("您没有可使用的NIPT检测免费券，不能进行此操作");
		return false;
	}

    //传递畸形儿类型数据
	var ckTestOtherInfo = $("#ckTestOther-input").val();
    if( ckTestOtherInfo !=""){
    	//-1表示“否”，传递空值
    	if(ckTestOtherInfo == "-1"){
            params.ckTestOther = "";
		}else {
            params.ckTestOther = ckTestOtherInfo;
		}

    }


	if($("#notes").val().length > 0){
		params.notes = $("#notes").val();
	}

    //传递B超异常数据
    var btypeAbnormalIn=$("#btypeAbnormal-input").val();
    if(btypeAbnormalIn !=""){
        params.btypeAbnormal = btypeAbnormalIn;
        if(btypeAbnormalIn == "1"){
            var btypeDesc= $("#btypeAbnormalDesc").val();
            if(btypeDesc !=""){
                params.btypeAbnormalDesc = btypeDesc;
            }else{
                alert("请输入B超异常信息！");
                return false;
            }

        }
    }

    //传递胎数数据
    if($("#btypeUltrasonic-input").val()!=""){
        params.btypeUltrasonic=$("#btypeUltrasonic-input").val();
    }

    //获取家族史
    params.familyProduce = $("#familyProduce").val();

    //获取临床诊断
    params.clinicalDiagnosis = $("#clinicalDiagnosis").val();

	//获取孕周
	params.gestationalWeeks = $("#gestationalWeeks1").val() + 'W+' + $("#gestationalWeeks2").val();

    //设置模板文件路径，对应前端工作平台1.0的模板服务器路径
    params.fileVer = "temp/Nifty.jsp";
	params.sourceType='1';

    //数据过滤 end   updateSampleBaseBySampleBaseId
    //console.log(JSON.stringify(params));
    $.ajax({
            type: 'POST',
            data: {
                method: isEdit ? 'updateExportSampleBases' : 'createSampleBase',
                ...params,
            sampleBaseId: isEdit ? sampleBaseId : undefined
        },
        url: '/csfy/intf.do',
        error: function (e) {
        sysErrorShow('操作失败!');
    },
    success: function (res) {
        if (res && res.code == 200) {
            alert(isEdit ? "修改送检单成功" : "保存送检单成功");
            if (!isEdit){
                window.location.href = window.location.pathname;
            }
            else{
                sessionStorage.setItem("sampleEditSuccess", "true");
            }


        } else if (res) {
            alert(res.msg ? res.msg : "操作失败")
        }
    }
});
}



//获取当前登录用户信息
$(document).ready(function () {
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: { method: 'getLoginUserInfo' },
        success: res => {
        if (res.code == 10086) {
        alert("请重新登录！");
    } else {
        if (res.code == 200) {
            $(".username").html(res.rows.userName);
        }
    }
}
})
})